﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Bymed.SpineScan.WPF.CustomizedUserControl;
using Bymed.SpineScan.WPF.Shared;
using Bymed.SpineScan.WPF.ViewModel;
using Bymed.SpineScan.WPF.ViewModel.TestItemViewModel;

namespace Bymed.SpineScan.WPF
{
    /// <summary>
    /// Interaction logic for TestReportWindow.xaml
    /// </summary>
    public partial class TestReportWindow : Window
    {
        public TestReportWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                AddPageContent();
            }
            catch (Exception ex)
            {
                MyViewModelBase.RequestDisplayErrorMessage(ex.Message);
            }
        }

        /// <summary>
        /// Add PageContent based on test result.
        /// </summary>
        private void AddPageContent()
        {
            var viewModel = DataContext as TestReportViewModel;

            // Check if need to display build-in test item result report.
            if (viewModel.TestItemList.Any(p => !p.IsCustomizedTestItem && p.NeedDetailReport))
            {
                ViewHelper.AddPageContent(CurrentFixedDocument, new BuildInTestResultReportContentUserControl(), DataContext);
            }

            // Check if need to add another FixedPage to display Customized Test Item Result.
            if (viewModel.TestItemList.Any(p => p.IsCustomizedTestItem && p.NeedDetailReport))
            {
                viewModel.BoundCustomizedTestItemList =
                    new ObservableCollection<SingleTestItemViewModel>(viewModel.TestItemList.Where(p => p.IsCustomizedTestItem && p.NeedDetailReport));

                ViewHelper.AddPageContent(CurrentFixedDocument, new CustomizedTestResultReportContentUserControl(), DataContext);
            }
        }
    }
}
